<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>社医堂</title>
<link rel="stylesheet" type="text/css" href="../../../css/hui.css" />
<link rel="stylesheet" type="text/css" href="../../../css/iconfont.css" />
</head>
<body>
<style type="text/css">
.hui-speed-dial ul li{width:33%;}
.hui-speed-dial-text{line-height:20px;}
#baocun{position:absolute;width:100%;margin-left:0%;bottom:0px;}
</style>
	


<div class="hui-wrap">

	
    <div class="hui-list" style="background:#FFFFFF;">
        <a href="javascript:void(0);" style="height:auto; height:80px; padding-bottom:8px;">
    		<div class="hui-list-icons" style="width:110px; height:80px;" onclick="avatar()">
    			<img src="../../../image/list/avatar.png" id="avatar" style="width:66px; margin:0px; border-radius:50%;" />
    		</div>
    		<div class="hui-list-text" style="height:79px; line-height:79px;">
    			<div class="hui-list-text-content" id="name">
    				
    			</div>
    			<div class="hui-list-info">
    				<span class="hui-icons hui-icons-right" onclick="toDetails('','edit')"></span>
    			</div>
    		</div>
    	</a>
    	<a href="javascript:void(0);">
    		<div class="hui-list-text">
    			积分 : 0 分
    		</div>
    	</a>
    </div>
	

	
    <div class="hui-list" style="background:#FFFFFF; margin-top:15px;">
        <ul>

			<li>
				<a href="javascript:void(0);" onclick="toDetails('','edit')">
					<div class="hui-list-icons">
						<img src="../../../image/list/account.png" />
					</div>
					<div class="hui-list-text">
						个人资料
						<div class="hui-list-info">
							<span class="hui-icons hui-icons-right"></span>
						</div>
					</div>
				</a>
			</li>
			<li>
				<a href="javascript:void(0);" onclick="band()">
					<div class="hui-list-icons">
						<img src="../../../image/list/each.png" />
					</div>
					<div class="hui-list-text">
						绑定医生
						<div class="hui-list-info">
							<span class="hui-icons hui-icons-right"></span>
						</div>
					</div>
				</a>
			</li>
			<li>
				<a href="javascript:void(0);" onclick="toDetails('','password')">
					<div class="hui-list-icons">
						<img src="../../../image/list/set.png" />
					</div>
					<div class="hui-list-text">
						修改密码
						<div class="hui-list-info">
							<span class="hui-icons hui-icons-right"></span>
						</div>
					</div>
				</a>
			</li>
					
            <li>
            	<a href="javascript:void(0);" onclick="toDetails('../news/','list',5);">
            		<div class="hui-list-icons">
    	    			<img src="../../../image/list/ht.png" />
    	    		</div>
    	    		<div class="hui-list-text">
    	    			帮助中心
    	    			<div class="hui-list-info">
    	    				<span class="hui-icons hui-icons-right"></span>
    	    			</div>
    	    		</div>
            	</a>
           	</li>
           	<li>
            	<a href="javascript:void(0);" onclick="toDetails('../news/','list',6);">
            		<div class="hui-list-icons">
    	    			<img src="../../../image/list/order.png" />
    	    		</div>
    	    		<div class="hui-list-text">
    	    			用户须知
    	    			<div class="hui-list-info">
    	    				<span class="hui-icons hui-icons-right"></span>
    	    			</div>
    	    		</div>
            	</a>
           	</li>
           	<li>
            	<a href="javascript:void(0);" onclick="toDetails('../news/','list',7);">
            		<div class="hui-list-icons">
    	    			<img src="../../../image/list/lishi.png" />
    	    		</div>
    	    		<div class="hui-list-text">
    	    			隐私协议
    	    			<div class="hui-list-info">
    	    				<span class="hui-icons hui-icons-right"></span>
    	    			</div>
    	    		</div>
            	</a>
           	</li>

			<li>
            	<a href="javascript:void(0);" onclick="update();">
            		<div class="hui-list-icons">
    	    			<img src="../../../image/list/loading.png" />
    	    		</div>
    	    		<div class="hui-list-text">
    	    			检查更新
    	    			<div class="hui-list-info">当前版本 <font id="version">0.0.15</font>
    	    				<span class="hui-icons hui-icons-right"></span>
    	    			</div>
    	    		</div>
            	</a>
           	</li>
			
			
			
        </ul>
    </div>
    <div style="background:#FFFFFF; margin-top:28px;">
        <button type="button" class="hui-button hui-button-large" onclick="loginout();">
        	<span class="hui-icons hui-icons-logoff"></span>退出系统
       	</button>
    </div>
	
	<div onclick="savepic()" id="baocun" type="button" class="hui-button hui-button-large" style="display:none;background-color:#666;color:#fff;;">保存照片</button>
	
</div>


<script src="../../../script/hui.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../script/hui-tab.js" type="text/javascript"></script>
<script src="../../../script/api.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../script/stm.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript">

apiready=function(){

	islogin(1)
	hui("#version").html(api.appVersion);
	
	getuser()
}


function getuser(){

	api.ajax({
        url: $api.getStorage('geturl')+'&c=ajaxmember&a=getuserinfo',
        method: 'post',
        data: {
            values: { 
                userid : $api.getStorage('userid')
            }
        }
    },function(ret, err){
        if (ret) {

            if (ret.status==1) {

				if(ret.data.member.avatar!=null && ret.data.member.avatar!=''){
                	document.getElementById("avatar").src = $api.getStorage('weburl')+"/"+ret.data.member.avatar;
				}

				if (ret.data.person.name=='' || ret.data.person.name==null) {
					hui("#name").html(ret.data.member.username)					
				}else{
					hui("#name").html(ret.data.person.name)
				}
				
            }
        } else {
            alert( JSON.stringify( err ) );
        }
    }); 
}

function person(){
    toDetails('','my',0);
}

function reg(){
    toDetails('','reg',0);
}

//调用摄像机拍照
function avatar(){

	api.getPicture({
		sourceType: 'camera',
		encodingType: 'png',
		mediaValue: 'pic',
		destinationType: 'url',
		allowEdit: true,
		quality: 100,
		targetWidth:100,
		targetHeight:100,
		saveToPhotoAlbum: false
	},function(ret,err){
		imagecli(ret.data)							
	});

}


//启动裁切
function imagecli(imgurl){

	var width = api.frameWidth;
	var height = api.frameHeight-100;
	var left = (width-300)/2;
	var top  = (height-300)/2;

	var FNImageClip = api.require('FNImageClip');
	FNImageClip.open({
		rect: {
			x: 0,
			y: 0,
			w: api.winWidth,
			h: api.winHeight-160
		},
		srcPath: imgurl,
		style: {
			mask: 'rgba(55,55,55,0.5)',
			clip: {
				w: 300,
				h: 300,
				x: left,
				y: top,
				borderColor: '#0f0',
				borderWidth: 1,
				appearance: 'rectangle'
			}
		},
		fixedOn: api.frameName
	}, function(ret, err) {
		if (ret) {
			if(ret.status==true){
				document.getElementById("baocun").style.marginTop = height+"px";
				document.getElementById("baocun").style.display = "block";
			}            
		} else {
			alert(JSON.stringify(err));
		}
	});

}

//保存裁切
function savepic(){

	var FNImageClip = api.require('FNImageClip');
	FNImageClip.save({
		destPath: 'fs://imageClip/result.png',
		copyToAlbum: false,
		quality: 1
	}, function(ret, err) {
		if (ret) {
			FNImageClip.close()
			document.getElementById("baocun").style.display = "none";
			upavatar(ret.destPath);			
		} else {
			alert(JSON.stringify(err));
		}
	});

}


//上传裁切后的图片
function upavatar(avatar){

	api.ajax({
		url: $api.getStorage('geturl')+'&c=ajaxmember&a=upload',
		method: 'post',
		timeout:30,
		data: {
			values: {
				folder: 'avatar',
				userid: $api.getStorage('userid'),
			},
			files: {
				upfile: avatar
			}
		}
	},function(ret, err){
		//alert(JSON.stringify(ret))
		submitsave(ret.data)
	});


}

//保存图片到数据库 
function submitsave(avatar){

	api.ajax({
		url: $api.getStorage('geturl')+'&c=ajaxmember&a=updateavatar',
		method: 'post',
		data: {
			values: { 
				userid : $api.getStorage('userid'),
				avatar: avatar,
			}
		}
	},function(ret, err){
		
		if (ret) {
			api.toast({msg:'头像保存成功'})	
			document.getElementById("avatar").src = $api.getStorage('weburl')+"/"+avatar;		
			//getuser()		
			//setTimeout("tomy()",1000)
		} else {
			alert( JSON.stringify( err ) );
		}
	}); 
}


function tomy(){
    toDetails('','my',0);
}


function update(){
	var mam = api.require('mam');
	mam.checkUpdate(function(ret, err) {
		if (ret) {
			var result = ret.result;
			if (result.update == true && result.closed == false) {
				var str = '新版本型号:' + result.version + ';更新提示语:' + result.updateTip + ';下载地址:' + result.source + ';发布时间:' + result.time;
				api.confirm({
					title : '有新的版本,是否下载并安装 ',
					msg : str,
					buttons : ['确定', '取消']
				}, function(ret, err) {
					if (ret.buttonIndex == 1) {
						if (api.systemType == "android") {
							api.download({
								url : result.source,
								report : true
							}, function(ret, err) {
								if (ret && 0 == ret.state) {/* 下载进度 */
									api.toast({
										msg : "正在下载应用" + ret.percent + "%",
										duration : 2000
									});
								}
								if (ret && 1 == ret.state) {/* 下载完成 */
									var savePath = ret.savePath;
									api.installApp({
										appUri : savePath
									});
								}
							});
						}
						if (api.systemType == "ios") {
							api.installApp({
								appUri : result.source
							});
						}
					}
				});
			} else {
				api.alert({
					msg : "暂无更新"
				});
			}
		} else {
			api.alert({
				msg : err.msg
			});
		}
	});

}



function band(){

	var FNScanner = api.require('FNScanner');
	FNScanner.open({
		autorotation: true
	}, function(ret, err) {
		if (ret) {
			if(ret.eventType=='success'){
				var str = ret.content
				if(str.indexOf("||")!==false){
					api.toast({msg: '医生二维码有误，请联系管理员解决0001',duration: 2000,location: 'top'});
					return false;
				}
				strArr = str.split("||")
				if(parseInt(strArr[1])<=0){
					api.toast({msg: '医生二维码有误，请联系管理员解决0002',duration: 2000,location: 'top'});
					return false;
				}
				api.ajax({
					url: $api.getStorage('geturl')+'&c=ajaxmember&a=banddocuser',
					method: 'post',
					data: {
						values: { 
							userid : $api.getStorage('userid'),
							docid  : strArr[1]
						}
					}
				},function(ret, err){
					if (ret) {
						$api.setStorage('docid',strArr[1]);
						api.alert({title: '重新绑定医生',  msg: "已经成功绑定了 "+strArr[0] });								
						//api.toast({msg: ret.tip,duration: 2000,location: 'top'});
					} else {
						api.toast({msg:"扫码出错001，请联系管理员",duration: 2000,location: 'top'});
					}
				}); 
			}
		} else {
			api.toast({msg:"扫码出错002，请联系管理员",duration: 2000,location: 'top'});
		}
	});
}
</script>

</body>
</html>